package com.samphanie.dries.service.impl;

import com.samphanie.dries.service.IEmailService;
import lombok.RequiredArgsConstructor;
import lombok.val;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;

/**
 * @Description:
 * @Author ZSY
 * @createTime 2021/3/4 14:18
 */
@Service
@RequiredArgsConstructor
@ConditionalOnProperty(prefix = "dries.email-provider", name = "name", havingValue = "smtp")
public class EmailServiceImpl implements IEmailService {

    private final JavaMailSender emailSender;

    @Override
    public void sendEmail(String email, String msg) {
        val message = new SimpleMailMessage();
        message.setTo(email);
        message.setFrom("1451691457@qq.com");
        message.setSubject("Spring Security 登录验证码");
        message.setText("验证码为:" + msg);
        emailSender.send(message);
    }

}
